﻿// 接口中定义事件、索引器、属性、方法：
using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{
    delegate void Delegate();

    interface I<T>
    {
        event Delegate DE;

        T this[int i]
        {
            get;
            set;
        }

        List<T> age
        {
            get;
            set;
        }

        void Say();
    }

    class C : I<C>
    {
        public event Delegate DE;

        public C this[int i]
        {
            get { return age[i]; }
            set { DE(); Say(); age[i] = value; }
        }

        public List<C> age
        {
            get;
            set;
        }

        public void Say()
        {
            Console.WriteLine("123");
        }
    }

    class B : I<C>
    {
        public event Delegate DE;

        public C this[int i]
        {
            get { return age[i]; }
            set { DE(); Say(); age[i] = value; }
        }

        public List<C> age
        {
            get;
            set;
        }

        public void Say()
        {
            Console.WriteLine("456");
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            I<C> Ic = new C();
            I<C> Ib = new B();

            Ic.DE += DeC;
            Ib.DE += DeB;
            Ib = Ic;
            Ib.age = new List<C>();
            Ib.age.Add(new C());
            Ib[0] = new C();
            Console.WriteLine("5");
            Console.ReadKey();
        }

        static void DeC()
        {
            Console.WriteLine("c");
        }
        static void DeB()
        {
            Console.WriteLine("b");
        }
    }
}